import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk'

// createSagaMiddleware导入的是一个函数
import createSagaMiddleware from 'redux-saga';

import saga from './saga'
import reducer from './reducer.js';

//composeEnhancers函数
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true}) || compose;    

//应用一些中间件
//引入thunkMiddleware中间件


//创建sagaMiddleware中间件
const SagaMiddleware = createSagaMiddleware(); 
const storeEnhancer = applyMiddleware(thunkMiddleware, SagaMiddleware);

const store = createStore(reducer, composeEnhancers(storeEnhancer));
// const store = createStore(reducer, storeEnhancer);

SagaMiddleware.run(saga);

export default store;